package com.hw.shortlink.admin.controller;

import com.hw.shortlink.admin.common.convention.response.Result;
import com.hw.shortlink.admin.common.convention.response.Results;
import com.hw.shortlink.admin.dto.req.GroupSaveReqDto;
import com.hw.shortlink.admin.dto.req.GroupSortReqDto;
import com.hw.shortlink.admin.dto.req.GroupUpdateReqDto;
import com.hw.shortlink.admin.dto.resp.GroupQueryRespDto;
import com.hw.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 新增短链接分组
     * @param groupSaveReqDto
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> createGroup(@RequestBody GroupSaveReqDto groupSaveReqDto){
        groupService.createGroup(groupSaveReqDto);
        return Results.success();
    }

    /**
     * 查询某个用户所有的Group
     * @return
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<GroupQueryRespDto>> listGroup(){
        return Results.success(groupService.listGroup());
    }

    /**
     * 修改分组信息
     * @param groupUpdateReqDto
     * @return
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateByGid(@RequestBody GroupUpdateReqDto groupUpdateReqDto){

        groupService.updateGroup(groupUpdateReqDto);
        return Results.success();
    }

    /**
     * 删除分组
     * @param gid
     * @return
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteByGid(@RequestParam("gid") String gid){

        groupService.deleteByGid(gid);
        return Results.success();
    }

    /**
     * 排序分组
     * @param list
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sortGroup(@RequestBody List<GroupSortReqDto> list){

        groupService.sortGroup(list);
        return Results.success();

    }



}
